import React from 'react'
import { NavBar, Space, Toast } from 'antd-mobile'
import { useNavigate } from 'react-router-dom'
import { Form, Input ,Button} from 'antd-mobile'
import { getLoginApi } from '../../api/qqApi'
function Index() {
  const nav=useNavigate()
  const [form]=Form.useForm()
  const onFinish = async (values) => {
    const info=await form.validateFields(values)
    console.log(info);
    const {data:res}= await getLoginApi(info)
    console.log(res);
    localStorage.setItem('token',res.token)
    // localStorage.setItem('name','zs')
    // localStorage.setItem('pic','/images/avatar.jpg')
    // localStorage.setItem('token','Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6OSwidXNlcm5hbWUiOiJ6cyIsInRlbCI6bnVsbCwidGVsQ29kZSI6IjJHUjgiLCJhdmF0YXIiOiIvaW1hZ2VzL2F2YXRhci5qcGciLCJpYXQiOjE3NDQ2MTI5NzEsImV4cCI6MTc0NzIwNDk3MX0.wPvySIcZJVhgAYyN1HwMeyBJOFEETnH4g-tJ5JX9rA4')
    nav('/home')
  }
  return (
    <div>
      <NavBar onBack={()=>nav(-1)}></NavBar>

      <div>
        <h5 style={{textAlign:'center',marginTop:'50px',fontSize:'25px'}}>登录</h5>

        <Form
        form={form}
        name='form'
        onFinish={onFinish}
        footer={
          <Button block type='submit' color='primary' size='large' 
          disablued={Input.value==''?true:false}>
            提交
          </Button>
          
        }
      >
         <Form.Item
                name='email'
                label='邮箱'
                rules={[
                  { required: true },
                 
                ]}
              >
                <Input placeholder='请输入邮箱' />
              </Form.Item>
        <Form.Item 
           label='密码'
           name='password'
           rules={[
            { required: true,message:'请输入密码' }
          ]} >
          <Input placeholder='请输入密码' />
        </Form.Item>
      </Form>
      </div>
      <p style={{textAlign:'center'}} onClick={()=>nav('/reg')}>去注册</p>
    </div>
  )
}

export default Index
